import eslint from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import eslintPluginImport from "eslint-plugin-import";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import pluginVue from "eslint-plugin-vue";
import tslint from "typescript-eslint";

export default [
  // 忽略
  { ignores: ["dist", "assets", "node_modules", "public", "vite.config.ts"] },
  {
    files: ["**/*.{js,ts,tsx,vue}"],
    languageOptions: {}
  },
  eslint.configs.recommended,
  ...tslint.configs.recommended,
  eslintConfigPrettier,
  // chosen vue defaults
  ...pluginVue.configs["flat/essential"],
  // vue
  {
    files: ["**/*.{js,ts,tsx,vue}"],
    languageOptions: {
      // parser: vueParser,
      parserOptions: {
        parser: tslint.parser // parse TS inside VUE
      }
    }
  },
  {
    files: ["**/*.{js,ts,tsx,vue}"],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module"
    },
    plugins: {
      "simple-import-sort": simpleImportSort,
      import: eslintPluginImport
    },
    rules: {
      // 对导入语句排序
      "simple-import-sort/imports": [
        "error",
        {
          groups: [
            // 1. 框架
            [`^vue$`, `^vue-router$`, `^ant-design-vue$`, `^echarts$`],
            // 2. 组件.vue 文件
            [`.*\\.vue$`],
            // 3. api
            [`.*/api/.*`, `^@/api$`],
            // 4. hooks
            [`.*/hooks/.*`, `^@/hooks$`],
            // 5. 路由
            [`.*/router/.*`, `^@/router$`],
            // 6. store
            [`.*/store/.*`, `^@/store$`],
            // 7. utils
            [`.*/utils/.*`, `^@/utils$`],
            [`^`], // 第三方模块
            [`^type `], // 类型文件
            // 将 CSS 文件放到最后
            [`.*/style.css$`, `^.*\\.css$`]
          ]
        }
      ],
      // 对导出的排序
      "simple-import-sort/exports": "error",
      // 导入 必须在第一行
      "import/first": "error",
      // import 后换行
      "import/newline-after-import": "error",
      // 禁止重复导入
      "import/no-duplicates": "error"
    }
  }
];
